﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Configuration;
using System.Linq;
using IB_report_stand.Objects;
using System.Collections.Generic;
using IB_report_stand.DAL;

namespace IB_report_stand
{
    public partial class rpt_debit_banking : DevExpress.XtraReports.UI.XtraReport
    {
         private DateTime _startDate;
        private DateTime _endDate;
        private TopMarginBand topMarginBand1;
        private DetailBand detailBand1;
        private BottomMarginBand bottomMarginBand1;
        private String _GLAccount;

        public rpt_debit_banking()
        {
            InitializeComponent();
        }



        public rpt_debit_banking(DateTime startDate, DateTime endDate, String GLAccount)
        {
            _startDate = startDate;
            _endDate = endDate;
            _GLAccount = GLAccount;

            InitializeComponent();

            lblStartDate.Text = _startDate.ToShortDateString();
            lblEndDate.Text = _endDate.ToShortDateString();
            lblAccount.Text = GLAccount;

            lblCompanyName.Text = ConfigurationManager.AppSettings["companyName"];
            lblCompanyAddress.Text = ConfigurationManager.AppSettings["companyAddress"];

            InitializeReport();
        }

       
        private void InitializeReport()
        {
            DataObjectsDataContext dataContext = new DataObjectsDataContext();
            var openValue = dataContext.func_report_bank_debit_open_period(_startDate, _GLAccount);
            var dataReport = from debitBank in dataContext.func_report_bank_debit(33395991, _startDate, _endDate, _GLAccount)
                             select debitBank;

            List<BankDebitObject> lstSource = new List<BankDebitObject>();


            double remainValue = 0;
            foreach (func_report_bank_debitResult item in dataReport)
            {
                BankDebitObject obj = new BankDebitObject();

                if (item.datum.HasValue)
                {
                    obj.DateReceipt = item.datum.Value;
                    obj.DateNote = item.datum.Value;
                }

                obj.NumberReceiptInput = item.receiptNumbIn;
                obj.NumberReceiptOutput = item.receiptNumbOut;
                obj.Description = item.oms25;

                if (item.debitAmount.HasValue)
                    obj.AmountIn = item.debitAmount.Value;

                if (item.creditAmount.HasValue)
                    obj.AmountOut = item.creditAmount.Value;

                if (item.remainAmount.HasValue)
                {
                    obj.AmountRemain = item.remainAmount.Value;
                    remainValue += item.remainAmount.Value;
                }

                obj.Note = item.docnumber;
                //lblOpenAmount.Text = openValue.ToString();
                //lblEndAmount.Text = remainValue.ToString();
                lstSource.Add(obj);
            }

            this.bindingSource.DataSource = lstSource;
        }

    }
}
